<?xml version="1.0" encoding="utf-8" ?>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<jsp:include page="/commonPart/htmlHeader2.jsp">
	<jsp:param name="title" value="修改登录密码-CommonWorld" />
</jsp:include>
<body>
<div id = "CW_Screen" >
	<jsp:include page= "/commonPart/bodyHeader2.jsp" ></jsp:include>
	<div id = "CW_Content">
		<div id = "SpaceLeft">
			<div class = "AdminNav clearfix">
				<a href = "${userUrls.home}" class = "u" title = "返回我的空间首页">
					<img src = "${userInfo.headImage}" alt = "${userInfo.name}" class = "SmallPortrait" user = "1" />	
				</a>
				<span class = "h">空间管理</span>
			</div>
			<div id = "AdminMenus" class = "Mod">
				<ul>
					<li class = "caption">
						<strong>个人信息管理</strong>
						<ol>
							<li><a href = "${userUrls.adminInbox}">站内留言</a></li>
							<li><a href = "${userUrls.adminProfile}">修改个人资料</a></li>
							<li class = "active"><a href = "${userUrls.adminChqwd}">更改登录密码</a></li>
							<li><a href = "${userUrls.adminPortrait}">更改头像图片</a></li>
						</ol>
					</li>
				</ul>
				<ul>
					<li class = "caption">
						<strong>博客管理</strong>
						<ol>
							<li><a href = "${userUrls.adminNewBlog}">发表博客</a></li>
							<li><a href = "${userUrls.adminDrafts}">草稿箱(${draftInfos.count})</a></li>
							<li><a href = "${userUrls.adminBlogCatalogs}">博客设置/分类管理</a></li>
						</ol>
					</li>
				</ul>
			</div>		
		</div>
		<div class = "SpaceList" id = "AdminBody">
			<div class = "TopBar">
			</div>
			<div class = "AdminHead">
				<h1>修改登录密码</h1>
			</div>
			<div class = "AdminContent MainForm">
				<form id = "change_pwd" action = "/user/profile/changePwd" method = "post">
					<table width = "100%">
						<tr>
							<th width = "150">旧的登录密码</th>
							<td>
								<input type = "password" name = "pwd" id = "pwd" size = '30' class = 'TEXT' tabindex = '1'>
							</td>
						</tr>
						<tr>
							<th>新密码</th>
							<td>
								<input type = "password" name = "newpwd" id = "newpwd" size = '30' class = 'TEXT' tabindex = '2'>
							</td>
						</tr>
						<tr>
							<th width = "150">再次输入新密码</th>
							<td>
								<input type = "password" name = "newpwd2" id = "newpwd2" size = '30' class = 'TEXT' tabindex = '3'>
							</td>
						</tr>
						
						<tr class = 'submit'>
							<th></th>
							<td>
								<input type = "submit" class = 'BUTTON SUMBIT' tabindex = '4' value = "修改密码">
								<span id = "error_msg" style = 'color: red; display: none;'></span>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<script src="/js/sha1.js?t=1377425784000"></script>
			<script>
				var old_pwd = "";
				var pwd = "";
				var pwd2 = "";
				$('#change_pwd').bind('form-pre-serialize', function(event, form, options, veto) {
					pwd = $('#newpwd').val();
					pwd2 = $('#newpwd2').val();
					old_pwd = $('#pwd').val();
					$('#newpwd').val(CryptoJS.SHA1(pwd));
			    	$('#newpwd2').val(CryptoJS.SHA1(pwd2));
			    	$('#pwd').val(CryptoJS.SHA1(old_pwd));
				});
				
				$('#change_pwd').ajaxForm({
					beforeSubmit: function(a, f, o) {
						if(pwd.length < 6){
			                $('#newpwd').focus();
			                $('#error_msg').html("密码长度小于6位");
			                $('#error_msg').show("fast");
							$('#newpwd').val(pwd);
							$('#newpwd2').val(pwd2);
							$('#pwd').val(old_pwd);
			                return false;
			            }
						
						if(pwd != pwd2){
			                $('#newpwd').focus();
							$('#error_msg').html("两次密码必须填写，且要匹配");
			                $('#error_msg').show("fast");
							$('#newpwd').val(pwd);
							$('#newpwd2').val(pwd2);
							$('#pwd').val(old_pwd);
			                return false;
						}

			            if(!pwd.match(/[0-9]/)||!(pwd.match(/[a-zA-Z]/)||/\W/.test(pwd))){
			                $('#newpwd').focus();
			                $('#error_msg').html("必须是字母或特殊符号和数字结合");
			                $('#error_msg').show("fast");
							$('#newpwd').val(pwd);
							$('#newpwd2').val(pwd2);
							$('#pwd').val(old_pwd);
			                return false;
			            }
					},
					success: function(response) {
						if (response.length > 0) {
							$('#error_msg').hide();
			        		$('#error_msg').html(response);
			        		$('#error_msg').show();
							$('#newpwd').val(pwd);
							$('#newpwd2').val(pwd2);
							$('#pwd').val(old_pwd);
			        	} else {
			        		$('#newpwd').val('');
							$('#newpwd2').val('');
							$('#pwd').val('');
			        		$('#error_msg').hide();
			        		$('#error_msg').html("密码修改成功！");
			        		$('#error_msg').show();
						}
					}
				});
			</script>
		</div>
	</div>
	<div class = "clear"></div>
	<div id = "footer"></div>
</div>
</body>
</html>